package GUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.io.IOException;

import javax.swing.JButton;

import Messages.MessageShowIDInventoryItem;
import Messages.MessageShowIDInventoryItemReply;

public class PanelFunctionsInventory extends PanelFunctionsEmpty {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton button_newItem;
	private JButton button_manualOrder;
	private JButton button_automaticalOrder;
	private JButton button_findItem;
	private JButton button_viewInventory;
	private JButton button_manageOrders;
	private MainMenu mainMenu;

	public PanelFunctionsInventory(MainMenu mm) {
		super(mm);
		this.mainMenu = mm;
		this.add(get_button_newItem());
		this.add(get_button_manualOrder());
		this.add(get_button_manageOrders());
		this.add( get_button_buildSchedule());
		// this.add(get_button_findItem());
		// this.add(get_button_viewInventory());

	}
	
	
	
	
	
private JButton get_button_buildSchedule()
	
	{
		JButton buildScheduleBtn=new JButton("סידור שולחנות חדש");
		buildScheduleBtn.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));				
		buildScheduleBtn.setPreferredSize(new Dimension(220, 30));
		buildScheduleBtn.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{ 
				((BorderLayout) mainMenu
						.getContentPane().getLayout())
						.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().add(new PfNewTableSchedule(mainMenu), BorderLayout.CENTER);							
				mainMenu.getContentPane().validate();			
			}								
		});
		return buildScheduleBtn;
	}

	private JButton get_button_manageOrders() {
		if (button_manageOrders == null) {
			button_manageOrders = new JButton("ניהול הזמנות");
			button_manageOrders.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_manageOrders.setPreferredSize(new Dimension(220, 30));

			button_manageOrders
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							//System.out.println("tables actionPerformed()");
							//MessageShowIDInventoryItem msgShowID = new MessageShowIDInventoryItem();

							try {
								//mainMenu.ms.client.sendToServer(msgShowID);
								//MessageShowIDInventoryItemReply resultID = (MessageShowIDInventoryItemReply) mainMenu.ms.client
									//	.GetMessage();
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								mainMenu.getContentPane().add(
										new PfManageOrders(mainMenu),
										BorderLayout.CENTER);
								mainMenu.getContentPane().validate();
								

							} catch (Exception e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
					});
		}
		return button_manageOrders;
	}

	private JButton get_button_newItem() {
		if (button_newItem == null) {
			button_newItem = new JButton("הכנסת פריט חדש");
			button_newItem.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_newItem.setPreferredSize(new Dimension(220, 30));

			button_newItem
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							System.out.println("tables actionPerformed()");
							MessageShowIDInventoryItem msgShowID = new MessageShowIDInventoryItem();

							try {
								mainMenu.ms.client.sendToServer(msgShowID);
								MessageShowIDInventoryItemReply resultID = (MessageShowIDInventoryItemReply) mainMenu.ms.client
										.GetMessage();
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								mainMenu.getContentPane().add(
										new PfAddNewInventoryItem(mainMenu,
												resultID.getResultID()),
										BorderLayout.CENTER);
								mainMenu.getContentPane().validate();
								

							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
					});
		}
		return button_newItem;
	}

	private JButton get_button_manualOrder() {
		if (button_manualOrder == null) {
			button_manualOrder = new JButton("הזמנה ידנית");
			button_manualOrder.setFont(new Font("Tahoma", Font.BOLD
					| Font.ITALIC, 15));
			button_manualOrder.setPreferredSize(new Dimension(220, 30));

			button_manualOrder
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							System.out.println("tables actionPerformed()");

							
								mainMenu.getContentPane()
										.remove(((BorderLayout) mainMenu
												.getContentPane().getLayout())
												.getLayoutComponent(BorderLayout.CENTER));
								mainMenu.getContentPane().add(
										new PfOrderItemManual(mainMenu),
										BorderLayout.CENTER);
								mainMenu.getContentPane().validate();
						}
					});
		}
		return button_manualOrder;
	}

	private JButton get_button_automaticalOrder() {
		if (button_automaticalOrder == null) {
			button_automaticalOrder = new JButton("הזמנה אוטומטית");
			button_automaticalOrder.setFont(new Font("Tahoma", Font.BOLD
					| Font.ITALIC, 15));
			button_automaticalOrder.setPreferredSize(new Dimension(220, 30));

			button_automaticalOrder
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							System.out.println("tables actionPerformed()");
						}
					});
		}
		button_automaticalOrder.setEnabled(false);
		return button_automaticalOrder;
	}

	private JButton get_button_findItem() {
		if (button_findItem == null) {
			button_findItem = new JButton("חיפוש פריט");
			button_findItem.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
					15));
			button_findItem.setPreferredSize(new Dimension(220, 30));

			button_findItem
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							System.out.println("tables actionPerformed()");
						}
					});
		}
		button_findItem.setEnabled(false);
		return button_findItem;
	}

	private JButton get_button_viewInventory() {
		if (button_viewInventory == null) {
			button_viewInventory = new JButton("הצג מלאי");
			button_viewInventory.setFont(new Font("Tahoma", Font.BOLD
					| Font.ITALIC, 15));
			button_viewInventory.setPreferredSize(new Dimension(220, 30));

			button_viewInventory
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							System.out.println("tables actionPerformed()");
						}
					});
		}
		button_viewInventory.setEnabled(false);
		return button_viewInventory;
	}
}